package com.wowjoy.dp.sds.service;

import com.google.common.base.Strings;
import com.wowjoy.dp.sds.domain.Dictionary;
import com.wowjoy.dp.sds.repoistory.DictionaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryService {

    @Autowired
    private DictionaryRepository dictionaryRepository;

    /**
     * 批量插入字典数据
     * @param dictionaryList 字典数据列表
     * @return 插入成功的条数
     */
    public Integer insertList(List<Dictionary> dictionaryList) {
        return dictionaryRepository.save(dictionaryList).size();
    }

    /**
     * 根据父节点ID获取所有枚举项
     * @param parentId 父节点ID
     * @return List<Dictionary>
     */
    public List<Dictionary> getByParentId(String parentId) {
        if (Strings.isNullOrEmpty(parentId)) {
            throw new NullPointerException("参数 patientId 为空");
        }
        return dictionaryRepository.findAllByParentId(parentId);
    }
}
